﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsGame4
{
    public class GameTimer
    {
        private float totalTime;
        public float timeInterval;
        public bool bMultiTrigger;
        public GameTimer(float timeInterval=-1)
        {
            bMultiTrigger=true;
            this.timeInterval = timeInterval;
            totalTime = 0;
        }
        public void Update(float dt)
        {
            totalTime += dt;
        }
        public bool IsTime(float dt)
        {
            Update(dt);
            return Time();
        }
        public bool IsTime()
        {
            return IsTime(GameManager.dt);
        }
        private bool Time()
        {
            if (timeInterval>0&&totalTime > timeInterval)
            {
                if (bMultiTrigger)
                    totalTime -= timeInterval;
                else totalTime = 0;
                return true;
            }
            else if (timeInterval == 0)
            {
                timeInterval = -1;
                return true;
            }
            else return false;
        }
    }
}
